var _mysql = require('mysql');


//var HOST = '172.16.1.100';
//var PORT = 3306;
var MYSQL_USER = 'chesh';
var MYSQL_PASS = 'amt123';
var DATABASE = 'myDatabase';

DataCollection = function(ihost,iport){
	this.mysql = _mysql.createConnection({
		host: ihost,
		port: iport,
		user: MYSQL_USER,
		password: MYSQL_PASS,
		insecureAuth: true,
	});
	this.mysql.connect(function(err) {
		if(err) {
			throw err;
		} else {
			console.log('Connected to database');
		}
	});
	this.mysql.query('use '+ DATABASE);

};

DataCollection.prototype.QueryCurRegs = function(callback) {
	this.mysql.query('SELECT a.sip_user, a.network_ip, a.user_agent FROM sip_registrations a', 
		function(err, results, fields){
			if(err){
				callback(err);
			}else{
				callback(null, results,fields);
			}
	});
}

DataCollection.prototype.QueryCurCalls = function(callback){
	this.mysql.query('SELECT a.cid_num, a.dest, a.created,a.call_uuid, a.b_uuid,a.callstate FROM basic_calls a',
		function(err,results,fields){
			if(err){
				callback(err);
			}else{
				callback(null,results,fields);
			}
	});
}
DataCollection.prototype.CloseConn = function() {
	this.mysql.end(function(err){
		if(err){
			throw err;
		}else{
			console.log('Disconnected from database\n!');
		}
	});
}

exports.DataCollection = DataCollection;
